﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>登录注册</title>
    <link rel="stylesheet" href="~/css/styleden.css">
    <script src="~/lib/jquery/jquery.min.js"></script>
    <script src="~/lib/jquery/jquery.metadata.js"></script>
    <script src="~/lib/jquery/jquery.validate.js"></script>
    <script src="~/lib/jquery/jquery.validate.messages_cn.js"></script>
</head>
<body>
    <!--登录-->
    <div id="login" class="content">
        <div class="form sign-in">
            <h2>欢迎回来</h2>
            <form method="post" action="/Home/Login">
                <label>
                    <span>邮箱/手机号</span>
                    <input type="text" id="lgname" name="name" />
                </label>
                <label>
                    <span>密码</span>
                    <input type="password" id="lgpwd" name="pwd" />
                </label>
                <p class="forgot-pass"><a href="javascript:">忘记密码？</a></p>
                <button type="submit" class="submit">登 录</button>
            </form>
        </div>
        <div class="sub-cont">
            <div class="img">
                <div class="img__text m--up">
                    <h2>还未注册？</h2>
                    <p>立即注册，发现大量机会！</p>
                </div>
                <div class="img__text m--in">
                    <h2>已有帐号？</h2>
                    <p>有帐号就登录吧，好久不见了！</p>
                </div>
                <div class="img__btn">
                    <span class="m--up">注 册</span>
                    <span class="m--in">登 录</span>
                </div>
            </div>
            <div class="form sign-up">
                <h2>立即注册</h2>
                <form method="post" action="">
                    <label>
                        <span>邮箱</span>
                        <input type="email" id="E_mail" onblur="checkem()" />
                    </label>
                    <label>
                        <span>手机号</span>
                        <input type="text" id="Mobile" onblur="checkmb()" />
                    </label>
                    <label>
                        <span>密码</span>
                        <input type="password" id="Password" onblur="checkpwd()" />
                    </label>
                    <label>
                        <span id="msg" style="color:red;align-content:center;"> </span>
                    </label>
                    <label>
                        <canvas id="canvas"  width="120" height="40"></canvas>
                        <input type="text" id="text">
                    </label>
                   
                    <button type="button" onclick="register()" class="submit">注 册</button>
                </form>
            </div>
        </div>
    </div>
    <script src="~/js/script.js"></script>
    <script type="text/javascript">
        function checkem() {
            $("#msg").empty();
        }
        function checkmb() {
            $("#msg").empty();
        }
        function checkpwd() {
            $("#msg").empty();
        }
        var num = null;

        /*验证*/
        function register() {
            var text = $("#text").val(); //获取输入框的值
            console.log(num);
            if (text != num) {
                alert('验证失败');
                return;
            }
            var email = $("#E_mail").val();
            var phone = $("#Mobile").val();
            var pwd = $("#Password").val();
            $.ajax({
                type: "post",
                url: "/Home/Register",
                data: { email: email, phone: phone, pwd: pwd },
                success: function (data) {
                    if (data == "") {
                        $("#lgname").val(email);
                        $("#lgpwd").val(pwd);
                        $("#login").removeClass("s--signup");
                    } else {
                        $("#msg").text(data)
                    }
                }
            })
        }
    @*验证码*@

        var canvas = document.getElementById("canvas");//演员
        var context = canvas.getContext("2d");//舞台，getContext() 方法可返回一个对象，该对象提供了用于在画布上绘图的方法和属性。
        var button = document.getElementById("bt");//获取按钮
        var input = document.getElementById("text");//获取输入框
        draw();
        canvas.onclick = function () {
            context.clearRect(0, 0, 120, 40);//在给定的矩形内清除指定的像素
            draw();
        }
        // 随机颜色函数
        function getColor() {
            var r = Math.floor(Math.random() * 256);
            var g = Math.floor(Math.random() * 256);
            var b = Math.floor(Math.random() * 256);
            return "rgb(" + r + "," + g + "," + b + ")";
        }
        function draw() {
            context.strokeRect(0, 0, 120, 40);//绘制矩形（无填充）
            var aCode = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
            // 绘制字母
            var arr = [] //定义一个数组用来接收产生的随机数
            for (var i = 0; i < 4; i++) {
                var x = 20 + i * 20;//每个字母之间间隔20
                var y = 20 + 10 * Math.random();//y轴方向位置为20-30随机
                var index = Math.floor(Math.random() * aCode.length);//随机索引值
                var txt = aCode[index];
                context.font = "bold 20px 微软雅黑";//设置或返回文本内容的当前字体属性
                context.fillStyle = getColor();//设置或返回用于填充绘画的颜色、渐变或模式，随机
                context.translate(x, y);//重新映射画布上的 (0,0) 位置，字母不可以旋转移动，所以移动容器
                var deg = 90 * Math.random() * Math.PI / 180;//0-90度随机旋转
                context.rotate(deg);// 	旋转当前绘图
                context.fillText(txt, 0, 0);//在画布上绘制“被填充的”文本
                context.rotate(-deg);//将画布旋转回初始状态
                context.translate(-x, -y);//将画布移动回初始状态
                arr[i] = txt //接收产生的随机数
            }
            num = arr[0] + arr[1] + arr[2] + arr[3] //将产生的验证码放入num
            // 绘制干扰线条
            for (var i = 0; i < 8; i++) {
                context.beginPath();//起始一条路径，或重置当前路径
                context.moveTo(Math.random() * 120, Math.random() * 40);//把路径移动到画布中的随机点，不创建线条
                context.lineTo(Math.random() * 120, Math.random() * 40);//添加一个新点，然后在画布中创建从该点到最后指定点的线条
                context.strokeStyle = getColor();//随机线条颜色
                context.stroke();// 	绘制已定义的路径
            }
            // 绘制干扰点，和上述步骤一样，此处用长度为1的线代替点
            for (var i = 0; i < 20; i++) {
                context.beginPath();
                var x = Math.random() * 120;
                var y = Math.random() * 40;
                context.moveTo(x, y);
                context.lineTo(x + 1, y + 1);
                context.strokeStyle = getColor();
                context.stroke();
            }

        }

    </script>
</body>
</html>
